import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../routes/app_routes.dart';

/// 错误页面视图
class ErrorView extends StatelessWidget {
  const ErrorView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 获取传递的错误消息参数
    final errorMessage = Get.arguments as String? ?? '发生未知错误';
    
    return Scaffold(
      appBar: AppBar(
        title: const Text('出错了'),
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // 错误图标
              const Icon(
                Icons.error_outline,
                size: 80,
                color: Colors.red,
              ),
              
              const SizedBox(height: 24),
              
              // 标题
              const Text(
                '出错了',
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                ),
              ),
              
              const SizedBox(height: 16),
              
              // 错误消息
              Text(
                errorMessage,
                textAlign: TextAlign.center,
                style: const TextStyle(
                  fontSize: 16,
                  color: Colors.grey,
                ),
              ),
              
              const SizedBox(height: 32),
              
              // 刷新按钮
              ElevatedButton(
                onPressed: () => Get.offAllNamed(AppRoutes.SPLASH),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 32,
                    vertical: 12,
                  ),
                ),
                child: const Text('重新加载'),
              ),
              
              const SizedBox(height: 16),
              
              // 返回首页按钮
              TextButton(
                onPressed: () {
                  if (Get.previousRoute.isNotEmpty) {
                    Get.back();
                  } else {
                    Get.offAllNamed(AppRoutes.HOME);
                  }
                },
                child: const Text('返回'),
              ),
            ],
          ),
        ),
      ),
    );
  }
} 